package com.information.manage.gyjc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.information.manage.basic.common.result.Result;
import com.information.manage.gyjc.mapper.GongzzMapper;
import com.information.manage.gyjc.model.enity.Gongzz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/gyjc/gongzz")
public class GongzzController {
    @Autowired
    private GongzzMapper gongzzMapper;

    // 查询工作站列表
    @GetMapping("/list/{curPage}/{size}")
    public Result selectGongzzList(@PathVariable Integer curPage, @PathVariable Integer size){
        Page<Gongzz> page = gongzzMapper.selectPage(new Page<>(curPage, size), null);
        return Result.ok(page);
    }

    // 查询所有工作站
    @GetMapping("/listAll")
    public Result listAll(){
        List<Gongzz> list = gongzzMapper.selectList(null);
        return Result.ok(list);
    }

    // 根据ID查询工作站
    @GetMapping("/select/{id}")
    public Result<Gongzz> selectGongzzById(@PathVariable Integer id){
        Gongzz gongzz = gongzzMapper.selectById(id);
        return Result.ok(gongzz);
    }

    // 添加工作站
    @PostMapping("/add")
    public Result<String> addGongzz(Gongzz gongzz) {
        int res = gongzzMapper.insert(gongzz);
        if (res > 0) {
            return Result.ok("添加成功");
        }
        return Result.fail("添加失败");
    }

    // 修改工作站
    @PostMapping("/update")
    public Result<String> updateGongzz(Gongzz gongzz) {
        int res = gongzzMapper.updateById(gongzz);
        if (res > 0) {
            return Result.ok("修改成功");
        }
        return Result.fail("修改失败");
    }

    // 删除工作站
    @DeleteMapping("/delete/{id}")
    public Result<String> deleteGongzz(@PathVariable Integer id) {
        int res = gongzzMapper.deleteById(id);
        if (res > 0) {
            return Result.ok("删除成功");
        }
        return Result.fail("删除失败");
    }
}
